//
//  KeyBoardView.m
//  Flava
//
//  Created by Ug-Code on 13-8-22.
//  Copyright (c) 2013年 UgCode. All rights reserved.
//

#import "KeyBoardView.h"

@implementation KeyBoardView

- (id)init
{
    self = [super init];
    if (self) {
        self.frame = CGRectMake(0, 0, 320, 55);
		_scrollView = [[UIScrollView alloc] init];
		_tagView = [[UGImageView alloc] init];
		//-- 
		_scrollView.frame = CGRectMake(0, 0, 210, 55);
		_scrollView.contentSize = CGSizeMake(435, 55);
		_tagView.frame = CGRectMake(210, 0, 110, 55);
		//-- 关闭滚动条
		_scrollView.showsHorizontalScrollIndicator = NO;
		_scrollView.showsVerticalScrollIndicator = NO;
		//-- 内容选择按钮框的背景图
		UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"scroll_view_bg.png"]];
		imageView.frame = CGRectMake(-320, 0, 1000, 55);
		[_scrollView addSubview:imageView];
		UIImageView *leftShadow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shadow_left.png"]];
		leftShadow.frame = CGRectMake(-7, 0, 7, 55);
		leftShadow.alpha = 0.5;
		[_tagView addSubview:leftShadow];
		_tagView.image = [UIImage imageNamed:@"tag_icon_bg.png"];
		// --添加按钮
		for (int i = 0; i < 8; i++) {
			UGButton *button = [[UGButton alloc] init];
			button.frame = CGRectMake(3 + (i*54), 3, 50, 50);
			button.tag = i+1;
			[button setNormalImageWithFile:[NSString stringWithFormat:@"attached_type_icon%02d_n.png", i+1]];
			[button setHighlightedImageWithFile:[NSString stringWithFormat:@"attached_type_icon%02d_h.png", i+1]];
			[button setSelectedImageWithFile:[NSString stringWithFormat:@"attached_type_icon%02d_s.png", i+1]];
			[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
			[_scrollView addSubview:button];
		}
		for (int i = 0; i < 2; i++) {
			UGButton *button = [[UGButton alloc] init];
			button.frame = CGRectMake(5+(50*i), 3, 50, 50);
			button.tag = i+98;
			[button setNormalImageWithFile:[NSString stringWithFormat:@"attached_type_icon%02d_n.png", i+98]];
			[button setHighlightedImageWithFile:[NSString stringWithFormat:@"attached_type_icon%02d_h.png", i+98]];
			[button setSelectedImageWithFile:[NSString stringWithFormat:@"attached_type_icon%02d_s.png", i+98]];
			[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
			[_tagView addSubview:button];
		}
		[self addSubview:_scrollView];
		[self addSubview:_tagView];
    }
    return self;
}

- (void)buttonClick:(UGButton *)button
{
	// 向通知中心广播按钮时间
	[[NSNotificationCenter defaultCenter] postNotificationName:@"FlavaKeyBoardViewButton" object:button];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
